<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>倒计时效果</title>
</head>

<body>
    <div id="box">
        跳转剩余时间：<span id="block">10</span>秒
    </div>
    <script>
        var box = document.getElementById('box');
        var block = document.getElementById('block');
        box.onclick = function () {
            var timer = setInterval(function () {
                if (block.innerText >= 1) {
                    block.innerText --;
                }else{
                    //清理定时器
                    clearInterval(timer);
                    //location：网址对象，浏览器中网址搜索区域。实现页面跳转。
                    location.href = 'http://www.baidu.com';
                }
            }, 1000);
        }
    </script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        #box {
            width: 300px;
            height: 100px;
            background-color: aquamarine;
            margin: 0 auto;
            font-size: 30px;
            text-align: center;
            line-height: 100px;
            top: 200px;
            left: 200px;
            position: absolute;
            /* 绝对位置 */
        }
    </style>
</body>

</html>